/**
 * author: leiqiao
 * dependencies: (underscore)
 */

var $utils = {};

$utils._ = {};
$utils._.counter = 0;
$utils._.prefix = 'id_';

$utils.setting_template = function () {
    /* 处理underscore和jsp的冲突 */
    if (_) {
        _.templateSettings = {
            interpolate: /\<\@\=(.+?)\@\>/gim,
            evaluate: /\<\@(.+?)\@\>/gim,
            escape: /\<\@\-(.+?)\@\>/gim
        };
    }
};

$utils.uuid = function () {
    var id = $utils._.prefix + $utils._.counter;
    $utils._.counter += 1;
    return id;
};

$utils.parse_query = function (s) {
    var obj = {};
    var a = s.substr(0).split('&');
    for (var i = 0; i < a.length; i++) {
        var b = a[i].split('=');
        obj[decodeURIComponent(b[0])] = decodeURIComponent(b[1] || '');
    }
    return obj;
};

$utils.pop = function (a, n) {
    var m = a.length - (n + 1), tmp = [], i;
    if (a.length > 0) {
        for (i = 0; i < m; i++) {
            tmp.push(a.pop());
        }
        a.pop();
        for (i = tmp.length - 1; i >= 0; i--) {
            a.push(tmp[i]);
        }
        return a;
    } else {
        return [];
    }
};